package likou;

import java.util.Comparator;
import java.util.PriorityQueue;

/**
 * @author: 唐小尊
 * @email: 1171702529@qq.com
 * @cate: 2021/08/08 10:48
 */
public class _5839 {
    public int minStoneSum(int[] piles, int k) {
        if (piles.length==0) return 0;
        PriorityQueue<Integer> priorityQueue = new PriorityQueue<>(new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o2-o1;
            }
        });
        int sum = 0;
        for (int num:piles){
            sum+=num;
            priorityQueue.add(num);
        }
        while (k!=0){
            k--;
            int now = priorityQueue.poll();
            sum -= now/2;
            priorityQueue.add(now - now/2);
        }
        return sum;
    }
}
